import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _dec4, _class, _class2;

/**
 * Oauth - 系统配置
 * @date: 2019-11-1

 * @version: 1.0.0
 */
import React, { Component } from 'react';
import { Col, Form, Input, Row, Select } from 'antd';
import { Bind } from 'lodash-decorators';
import Switch from 'components/Switch';
import Upload from 'components/Upload/UploadButton';
import intl from 'utils/intl';
import { BKT_PUBLIC } from 'utils/config';
var FormItem = Form.Item;
var formLayout = {
  labelCol: {
    span: 6
  },
  wrapperCol: {
    span: 18
  }
};
var Oauth = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_Component) {
  _inherits(Oauth, _Component);

  var _super = _createSuper(Oauth);

  function Oauth(props) {
    var _this;

    _classCallCheck(this, Oauth);

    _this = _super.call(this, props);
    _this.state = {};
    return _this;
  }

  _createClass(Oauth, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          languageList = _this$props.languageList,
          getFieldDecorator = _this$props.form.getFieldDecorator,
          _this$props$config$da = _this$props.config.data,
          data = _this$props$config$da === void 0 ? [] : _this$props$config$da;
      var logoFileList = [];

      if (data.length > 0) {
        data.forEach(function (item) {
          switch (item.configCode) {
            case 'COTH.LOGO_URL':
              logoFileList = [{
                uid: '-1',
                name: item.fileName,
                status: 'done',
                url: item.configValue
              }];
              break;

            default:
              break;
          }
        });
      }

      var loginTitle = this.findConfigField('COTH.TITLE', data);
      var copyright = this.findConfigField('COTH.COPYRIGHT', data);
      var loginLogo = this.findConfigField('COTH.LOGO_URL', data);
      var languageFlag = this.findConfigField('COTH.SHOW_LANGUAGE', data);
      var language = this.findConfigField('COTH.DEFAULT_LANGUAGE', data);
      return /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.loginTitle').d('登录页面标题')
      }, formLayout), getFieldDecorator('loginTitle', {
        initialValue: loginTitle,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cpfm.config.model.config.loginTitle').d('登录页面标题')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.copyright').d('版权信息')
      }, formLayout), getFieldDecorator('copyright', {
        initialValue: copyright,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cpfm.config.model.config.copyright').d('版权信息')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null))))), /*#__PURE__*/React.createElement(Row, {
        style: {
          display: 'none'
        }
      }, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.languageFlag').d('是否展示多语言')
      }, formLayout), getFieldDecorator('languageFlag', {
        initialValue: languageFlag === '1' ? 1 : 0
      })( /*#__PURE__*/React.createElement(Switch, null))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.logo').d('LOGO'),
        extra: intl.get('cpaas.common.upload.support', {
          type: '*.png;*.jpeg'
        }).d('上传格式：*.png;*.jpeg')
      }, formLayout), /*#__PURE__*/React.createElement(Upload, {
        accept: ".jpeg,.png",
        fileType: "image/jpeg,image/png",
        single: true,
        bucketName: BKT_PUBLIC,
        bucketDirectory: "cpfm05",
        onUploadSuccess: this.onUploadSuccess,
        fileList: logoFileList,
        onRemoveSuccess: this.onCancelSuccess
      })), /*#__PURE__*/React.createElement(FormItem, {
        wrapperCol: {
          span: 15,
          offset: 7
        }
      }, getFieldDecorator('loginLogo', {
        initialValue: loginLogo
      })( /*#__PURE__*/React.createElement("div", null))))), /*#__PURE__*/React.createElement(Row, {
        style: {
          display: 'none'
        }
      }, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.language').d('默认语言')
      }, formLayout), getFieldDecorator('language', {
        initialValue: language,
        rules: [{
          required: false,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cpfm.config.model.config.language').d('默认语言')
          })
        }]
      })( /*#__PURE__*/React.createElement(Select, null, languageList.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: item.value,
          value: item.value
        }, item.meaning);
      })))))));
    }
    /**
     * 从配置列表查找配置项
     * @param {Number|String} field 查询配置字段的 ID 或 Code
     * @param {Array} data 获取到的原配置数组
     */

  }, {
    key: "findConfigField",
    value: function findConfigField(field, data) {
      if (data.length > 0) {
        var dataFilter = data.find(function (item) {
          return item.configCode === field;
        });
        return dataFilter ? dataFilter.configValue : null;
      }
    } // 上传图片成功

  }, {
    key: "onUploadSuccess",
    value: function onUploadSuccess(file) {
      var form = this.props.form;

      if (file) {
        form.setFieldsValue({
          loginLogo: file.response
        });
      }
    } // 删除图片成功

  }, {
    key: "onCancelSuccess",
    value: function onCancelSuccess() {
      var form = this.props.form;
      form.setFieldsValue({
        loginLogo: ''
      });
    }
  }]);

  return Oauth;
}(Component), (_applyDecoratedDescriptor(_class2.prototype, "findConfigField", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "findConfigField"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "onUploadSuccess", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "onUploadSuccess"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "onCancelSuccess", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "onCancelSuccess"), _class2.prototype)), _class2)) || _class);
export { Oauth as default };